from selenium.webdriver.common.by import By
import time
from common.Utils import TestDriver
import datetime
from selenium.webdriver.common.keys import Keys

#测试论坛首页
class Homepage:
    url = ""
    driver = ""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-in.html"
        self.driver = TestDriver.driver
        self.driver.get(self.url)

    def HomepageSearch(self):
        self.driver.implicitly_wait(3)
        #登录成功
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("lisi")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        actual1 = self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert actual1 == "首页"
        #测试搜索功能
        #存在的
        search = self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input")
        search.send_keys("12312")
        search.send_keys(Keys.ENTER)
        time.sleep(1)
        TestDriver.getScreeShot()
        #不存在的
        search = self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input")
        search.send_keys("INVALID")
        search.send_keys(Keys.ENTER)
        time.sleep(1)
        TestDriver.getScreeShot()

    def HomepageNight(self):
        self.driver.implicitly_wait(3)
        # 登录成功
        #测试黑夜模式
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg").click()
        TestDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg").click()
        TestDriver.getScreeShot()


    def HomepageButton(self):
        self.driver.implicitly_wait(3)
        # 登录成功
        #测试各种按钮和信息
        time.sleep(2)
        #同类已经省略
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1 > a > img")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg")
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar")
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_nickname")
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_name_sub")
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a")
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(2) > a")
        self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title")
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div > div > div.col-auto > span")
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div > div > div.col > div.text-truncate > a > strong")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")
        TestDriver.getScreeShot()



homepage = Homepage()
homepage.HomepageSearch()
homepage.HomepageNight()
homepage.HomepageButton()